package com.tongzhou.tongzhou.message.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.message.dao.IMessageDAO;
import com.tongzhou.tongzhou.message.model.Message;
import com.tongzhou.tongzhou.message.model.SearchMessageCondition;

public class MessageAction extends ActionSupport{
	private String company_name;//公司名称
	private String company_num;//公司编号
	private List<Message> result=null;
	private SearchMessageCondition condition=null;
	
	private int pageSize ;
	private int currentPage ;
	private String orderBy ;
	private String orderByType ;
	
	private IMessageDAO dao=null;
	/**
	 * 备注列表界面
	 *@author: 彭定雄
	 *@return 
	 *@throws DBException
	 */
	public String listMessage() throws DBException{
		checkSearchCondition();
		condition = new SearchMessageCondition();
		if (currentPage == 0){
			currentPage = 1;
		}
		condition.setCurrentPage(currentPage) ;
		condition.setCompany_name(company_name);
		condition.setCompany_num(company_num);
		condition.setOrderBy(orderBy);
		condition.setOrderByType(orderByType) ;
		condition.setPageSize(pageSize) ;
	    result = dao.listMessage(condition);
		return "listMessage";
	} 
	
	
	/**
	 * 设置列表显示格式
	 *@author: 彭定雄
	 */
	private void checkSearchCondition(){
		if(currentPage <=0){
			currentPage = 1 ;
		}
		
		if(pageSize<=0){
			pageSize = 10 ;
		}
		
		if(orderBy==null||"".equals(orderBy)){
			orderBy = "id" ;
		}
		
		if(orderByType == null || "".equals(orderByType)){
			orderByType = "desc" ;
		}
	}


	public String getCompany_name() {
		return company_name;
	}


	public void setCompany_name(String companyName) {
		company_name = companyName;
	}


	public String getCompany_num() {
		return company_num;
	}


	public void setCompany_num(String companyNum) {
		company_num = companyNum;
	}


	public List<Message> getResult() {
		return result;
	}


	public void setResult(List<Message> result) {
		this.result = result;
	}


	public SearchMessageCondition getCondition() {
		return condition;
	}


	public void setCondition(SearchMessageCondition condition) {
		this.condition = condition;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public String getOrderBy() {
		return orderBy;
	}


	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}


	public String getOrderByType() {
		return orderByType;
	}


	public void setOrderByType(String orderByType) {
		this.orderByType = orderByType;
	}


	public IMessageDAO getDao() {
		return dao;
	}


	public void setDao(IMessageDAO dao) {
		this.dao = dao;
	}
}
